package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.example.EmpContractExample.*;

/**
 * 员工合同信息
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpContractQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_CONTRACT_ID, example = E_CONTRACT_ID)
    private Long contractId;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_TYPE, example = E_TYPE)
    @Length(max = 100)
    private String type;

    /**
     * 开始时间查询范围
     */
    @ApiParam(value = N_START_TIME_START, example = E_START_TIME_START)
    private Date startTimeStart;
    @ApiParam(value = N_START_TIME_END, example = E_START_TIME_END)
    private Date startTimeEnd;


    /**
     * 结束时间查询范围
     */
    @ApiParam(value = N_END_TIME_START, example = E_END_TIME_START)
    private Date endTimeStart;
    @ApiParam(value = N_END_TIME_END, example = E_END_TIME_END)
    private Date endTimeEnd;


    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 255)
    private String name;

    @ApiParam(value = N_TERM_YEAR, example = E_TERM_YEAR)
    private Integer termYear;

    @ApiParam(value = N_TERM_MONTH, example = E_TERM_MONTH)
    private Integer termMonth;

    @ApiParam(value = N_TERM_DAY, example = E_TERM_DAY)
    private Integer termDay;

    @ApiParam(value = N_REMARK, example = E_REMARK)
    @Length(max = 2147483647)
    private String remark;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = "员工姓名/合同名称/手机号")
    private String userNameOrConNameOrPhone;

    @ApiParam(value = "签署人B的账户id")
    private List<String> partyBAccountIds;

    @ApiParam(value = "员工状态 1：待入职，2：入职，3：待离职，4：离职")
    private Integer empStatus;

    /**
     * 签署完成时间查询范围
     */
    @ApiParam(value = "签署完成时间开始范围")
    private Date signFinishDateStart;
    @ApiParam(value = "签署完成时间结束范围")
    private Date signFinishDateEnd;

    @ApiParam(value = "即将到期")
    private Boolean willExpire;

    @ApiParam(value = "已经到期")
    private Boolean alreadyExpire;

    @ApiParam(value = "单人合同大于等于两份（合同类型仅包括固定期限劳动合同、劳务合同、劳务派遣合同）")
    private Boolean exceedDouble;

    @ApiParam(value = "身份证号")
    private String idCard;

    @ApiParam(value = "用工单位idList")
    private List<String> companyIdList;

    @ApiParam(value = "是否只查询纸质合同")
    private Boolean isEntity;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;

    /**
     * 导出相关字段
     */
    @ApiParam(value = "导出列")
    private List<EmpInfoExportColumn> exportColumns;

    /**
     * 英文名，用于模版路径 英文名 + Template.xlsx
     */
    @ApiParam(value = "英文名，用于模版路径 英文名 + Template.xlsx")
    private String enName;

    /**
     * id list
     */
    private List<String> idList;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpContractQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

